#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "securec.h"
#include "cmsis_os2.h"
#include "ohos_init.h"
#include "ohos_types.h"
#include "FreeRTOS.h"
#include "../utils_log.h"

static osThreadId_t g_tid = NULL;
#define POLL_TIMEOUT_TICS    pdMS_TO_TICKS(1000)
#define MAX_LOG_INTERVAL    60

void LogTestTask(void)
{
    uint32_t logInterval = 0; 
    uint32_t testCount = 0;
    while (1){
        logInterval++;
        if (logInterval == MAX_LOG_INTERVAL) {
            testCount++;
            LOG_TO_FILE("log test %d",testCount);
            logInterval=0;
        }
        osDelay(POLL_TIMEOUT_TICS);
    }
}

int StartLogTestTask(void)
{
    osThreadAttr_t attr;
    attr.name = "LOG_TEST_TASK";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 0x2100;
    attr.priority = 25;

    g_tid = osThreadNew((osThreadFunc_t)LogTestTask, NULL, &attr);
    if (g_tid == NULL) {
        printf("Failed to create log test task!\n");
        return -1;
    }
    printf("succeed to create log test task!\n");
    return 0;
}

void StopLogTestTask(void)
{
    if (NULL == g_tid) {
        return;
    }

    osThreadTerminate(g_tid);
    g_tid = NULL;
}